package com.example.chatchatbackend.Controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.chatchatbackend.entity.RestBean;
import com.example.chatchatbackend.entity.dto.Notice;
import com.example.chatchatbackend.entity.vo.request.NoticeVO;
import com.example.chatchatbackend.service.NoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 丁真
 * @since 2024-10-28 05:03:47
 */
@Slf4j
@RestController
@RequestMapping("/api/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    @GetMapping
    public RestBean<List<NoticeVO>> getAllComment(){
        return RestBean.success(noticeService.getAllNotice());
    }

    @PostMapping
    public RestBean<NoticeVO> insertNotice(@RequestBody NoticeVO noticeVO){
        NoticeVO insertNoticeVO = noticeService.insertNotice(noticeVO);
        return RestBean.success(insertNoticeVO);

    }

    @PostMapping("/list")
    public RestBean<List<NoticeVO>> insertNoticeList (@RequestBody List<NoticeVO> noticeVO){
        List<NoticeVO> NoticeList = noticeService.insertNoticeList(noticeVO);
        return RestBean.success(NoticeList);
    }

    @GetMapping("/pageThree")
    public RestBean<IPage<Notice>> pageThree(@RequestParam(value = "pageNum" ,defaultValue = "1") Integer pageNum,
                                               @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
        return RestBean.success(noticeService.pageThree(pageNum, pageSize));
    }

    @PutMapping
    public RestBean<NoticeVO> updateNotice(@RequestBody NoticeVO noticeVO){
        return RestBean.success(noticeService.updateNotice(noticeVO));

    }

    @DeleteMapping("/ids")
    public RestBean<String> delete(@RequestBody List<Integer> ids) {
        noticeService.deleteByIds(ids);
        return RestBean.success("删除成功");
    }

    @GetMapping("/name")
    public RestBean<List<NoticeVO>> findByTitle(@RequestBody String title ){
        List<NoticeVO> noticeVOList = noticeService.findByTitle(title);
        return RestBean.success(noticeVOList);
    }

}
